package com.gientech.orderSeata.controller;

import com.gientech.orderSeata.dao.OrderDao;
import com.gientech.orderSeata.domain.Order;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class OrderController {
    @Autowired
    private OrderDao orderDao;

    @Autowired
    public RestTemplate restTemplate;

    @GetMapping("/addOrder")
    @GlobalTransactional
    public String addOrder(){
        Order order = new Order();
        order.setProductId(99991234);
        order.setTotalAmount(9999999);
        order.setStatus(1);

        int n = orderDao.addOrder(order);
        System.out.println("添加状态：" + n);

        String s = restTemplate.getForObject("http://localhost:8010/addStock",String.class);

        System.out.println("返回的信息：" + s);

        return s;
    }
}
